/*     */ package com.newcrm.webapi;
/*     */ 
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.db.DealFieldManager;
/*     */ import com.newcrm.exception.DBException;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.ParameterUtil;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.sub.AddUpdatePeople;
/*     */ import com.newcrm.webapi.sub.ConfirmDestroyCustomer;
/*     */ import com.newcrm.webapi.sub.DeleteCustomer;
/*     */ import com.newcrm.webapi.sub.DeleteCustomerAvatar;
/*     */ import com.newcrm.webapi.sub.MergeCustomer;
/*     */ import com.newcrm.webapi.sub.ShowNewPeople;
/*     */ import com.newcrm.webapi.sub.ShowPeople;
/*     */ import com.newcrm.webapi.sub.ShowUpdatePeople;
/*     */ import com.newcrm.webapi.sub.UpdateAvatar;
/*     */ import java.io.IOException;
/*     */ import java.sql.SQLException;
/*     */ import java.util.List;
/*     */ import javax.servlet.RequestDispatcher;
/*     */ import javax.servlet.ServletConfig;
/*     */ import javax.servlet.ServletContext;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class People extends AbstractHttpServlet
/*     */ {
/*     */   private static final long serialVersionUID = -7647630656875983214L;
/*  39 */   private static Logger logger = Logger.getLogger(People.class.getName());
/*     */ 
/*     */   public void doGet(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/*  54 */     if (!checkLogin(request)) {
/*  55 */       super.showLoginPage(request, response);
/*  56 */       return;
/*     */     }
/*  58 */     String url = request.getRequestURI();
/*  59 */     String[] param = ParameterUtil.getParameters(url, getTagkey());
/*     */ 
/*  61 */     if ((param != null) && (param.length == 2))
/*     */     {
/*  63 */       if ("duplicates".equals(param[1])) {
/*  64 */         int id = Util.str2Int(param[0]);
/*  65 */         request.setAttribute("id", param[0]);
/*  66 */         request.setAttribute("isPerson", "1");
/*  67 */         CustomerManager manager = new CustomerManager();
/*  68 */         String customerName = manager.getName(id);
/*  69 */         if (customerName == null) {
/*  70 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/*  71 */             request, response);
/*  72 */           return;
/*     */         }
/*  74 */         request.setAttribute("name", customerName);
/*  75 */         request.getRequestDispatcher("/customer_duplicates.jsp")
/*  76 */           .forward(request, response);
/*  77 */         return;
/*     */       }
/*     */ 
/*  81 */       if ("avatar".equals(param[1])) {
/*  82 */         int id = Util.str2Int(param[0]);
/*  83 */         String path = getServletConfig().getServletContext()
/*  84 */           .getRealPath("images/upload/people/");
/*  85 */         UpdateAvatar action = new UpdateAvatar(this, id, path, true);
/*     */         try {
/*  87 */           action.parse(request, response);
/*     */         } catch (NotFoundException e) {
/*  89 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/*  90 */             request, response);
/*     */         }
/*  92 */         return;
/*     */       }
/*     */     }
/*     */ 
/*  96 */     if ((param != null) && (param.length == 3) && (param[0] != null) && 
/*  97 */       (param[0].length() > 0))
/*     */     {
/*  99 */       if (("avatar".equals(param[1])) && 
/* 100 */         ("delete".equals(param[2]))) {
/* 101 */         int id = Util.str2Int(param[0]);
/* 102 */         DeleteCustomerAvatar action = new DeleteCustomerAvatar(this, 
/* 103 */           id, true);
/*     */         try {
/* 105 */           action.parse(request, response);
/*     */         } catch (NotFoundException e) {
/* 107 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/* 108 */             request, response);
/*     */         }
/* 110 */         return;
/*     */       }
/*     */ 
/* 114 */       if (("deals".equals(param[1])) && 
/* 115 */         ("new".equals(param[2]))) {
/* 116 */         CustomerManager manager = new CustomerManager();
/* 117 */         int id = Util.str2Int(param[0]);
/* 118 */         String customerName = manager.getName(id);
/* 119 */         if (customerName != null) {
/* 120 */           request.setAttribute("customerId", param[0]);
/* 121 */           request.setAttribute("customerName", customerName);
/* 122 */           request.setAttribute("customerType", Integer.valueOf(1));
/*     */         }
/*     */ 
/* 125 */         DealFieldManager dealFieldManager = new DealFieldManager();
/* 126 */         User user = super.getLoginUser(request);
/*     */         try {
/* 128 */           List fields = dealFieldManager
/* 129 */             .list(user.companyId);
/* 130 */           request.setAttribute("fields", fields);
/*     */         } catch (DBException e) {
/* 132 */           logger.warn("get deal customer filed info failed", e);
/*     */         } catch (SQLException e) {
/* 134 */           logger.warn("get deal customer filed info failed", e);
/*     */         }
/* 136 */         request.getRequestDispatcher("/deal_new.jsp").forward(request, 
/* 137 */           response);
/* 138 */         return;
/*     */       }
/*     */ 
/* 142 */       if ("duplicates".equals(param[1])) {
/* 143 */         int oldId = Util.str2Int(param[0]);
/* 144 */         int newId = Util.str2Int(param[2]);
/*     */ 
/* 146 */         MergeCustomer action = new MergeCustomer(this, oldId, newId, 
/* 147 */           true);
/*     */         try {
/* 149 */           action.parse(request, response);
/*     */         } catch (NotFoundException e) {
/* 151 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/* 152 */             request, response);
/*     */         }
/* 154 */         return;
/*     */       }
/*     */     }
/*     */ 
/* 158 */     super.doGet(request, response);
/*     */   }
/*     */ 
/*     */   protected AbstractAction getAddAction()
/*     */   {
/* 163 */     return new AddUpdatePeople(this, null, getServletConfig()
/* 164 */       .getServletContext().getRealPath("lucene/"));
/*     */   }
/*     */ 
/*     */   protected AbstractAction getDeleteAction(String id)
/*     */   {
/* 169 */     return new DeleteCustomer(this, id, getServletConfig()
/* 170 */       .getServletContext().getRealPath("lucene/"));
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowAction(String id)
/*     */   {
/* 175 */     return new ShowPeople(this, id);
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowAddPageAction()
/*     */   {
/* 180 */     return new ShowNewPeople(this);
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowUpdatePageAction(String id)
/*     */   {
/* 185 */     return new ShowUpdatePeople(this, id);
/*     */   }
/*     */ 
/*     */   protected String getTagkey()
/*     */   {
/* 190 */     return "/people";
/*     */   }
/*     */ 
/*     */   protected AbstractAction getUpdateAction(String id)
/*     */   {
/* 195 */     return new AddUpdatePeople(this, id, getServletConfig()
/* 196 */       .getServletContext().getRealPath("lucene/"));
/*     */   }
/*     */ 
/*     */   protected AbstractAction getListAction()
/*     */   {
/* 201 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowConfirmDestroyAction(String id)
/*     */   {
/* 206 */     return new ConfirmDestroyCustomer(this, id, true);
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.People
 * JD-Core Version:    0.6.1
 */